<template>
    <div id="order-manage">
        <div class="title">
            <h1>订单管理</h1>
        </div>
        <div class="searchInfo">
            <el-form ref="form" :model="search_Data" label-width="80px" size="medium" :label-position="labelPosition"
                style="text-align:right ;">
                <div class="search_col_top">
                    <el-form-item label="开始时间">
                        <el-date-picker type="date" placeholder="选择开始日期" v-model="search_Data.startTime"
                            style="width: 150px" value-format="yyyy-MM-dd" clearable></el-date-picker>
                    </el-form-item>
                    <el-form-item label="结束时间">
                        <el-date-picker type="date" label-width="50px" placeholder="选择结束日期"
                            v-model="search_Data.overTime" style="width: 150px" clearable value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="区域">
                        <el-select v-model="search_Data.areaData" placeholder="请选择活动区域" style="width: 150px" clearable>
                            <el-option label="全部" value=""></el-option>
                            <el-option label="单人明区" value="1"></el-option>
                            <el-option label="单人暗区" value="2"></el-option>
                            <el-option label="双人室内" value="3"></el-option>
                            <el-option label="双人阅读区" value="4"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="订单状态">
                        <el-select v-model="search_Data.order_stateData" placeholder="请选择活动区域" style="width: 150px"
                            clearable>
                            <el-option label="全部" value=""></el-option>
                            <el-option label="未开始" value='6'></el-option>
                            <el-option label="进行中" value='1'></el-option>
                            <el-option label="已取消" value="2"></el-option>
                            <el-option label="已完成" value="3"></el-option>
                            <el-option label="已改期" value="4"></el-option>
                            <el-option label="已失效" value="5"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="订单号">
                        <el-input v-model="search_Data.order_id" style="width: 130px" clearable>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="手机号">
                        <el-input v-model="search_Data.Phone_num" style="width: 150px" clearable>
                        </el-input>
                    </el-form-item>
                    <el-button type="info" @click="onSearchBtn">查询</el-button>
                </div>
            </el-form>

        </div>
        <!-- 表格 -->
        <el-table :data="orderTableData" tooltip-effect="dark" style="width: 100%;line-height: 0; margin-top: 20px;">
            <el-table-column prop="createTime" label="下单时间" width="180" align="left">
            </el-table-column>
            <el-table-column prop="area" label="区域" align="center" width="180">
            </el-table-column>
            <el-table-column prop="orderTime" label="预约时间" align="center" width="280">
            </el-table-column>
            <!-- <el-table-column prop="orderPrice" label="订单金额" align="center">
            </el-table-column> -->
            <el-table-column prop="couponName" label="卡券抵扣" align="center">
            </el-table-column>
            <el-table-column prop="money" label="实际支付" align="center">
            </el-table-column>
            <el-table-column prop="state" label="订单状态" align="center">
                <template slot-scope="scope">
                    <span>{{
                            scope.row.state == 1
                                ? "进行中"
                                : scope.row.state == 2
                                    ? "已取消"
                                    : scope.row.state == 3
                                        ? "已完成"
                                        : scope.row.state == 4
                                            ? "已改期"
                                            : scope.row.state == 5
                                                ? "已失效"
                                                : scope.row.state == 6
                                                    ? "未开始"
                                                    : "异常订单"
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="no" label="订单号" align="center" width="180">
            </el-table-column>
            <el-table-column prop="tel" label="手机号" align="center" width="180">
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="100" align="center">
                <template slot-scope="scope">
                    <el-button @click="cancelOrderId(scope.row)" type="text" size="small">取消订单</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination style="float:right" @current-change="changePage" :current-page.sync="page" :page-size="limit"
            layout="prev, pager, next" :total="total">
        </el-pagination>
    </div>
</template>

<script>
export default {
    data() {
        return {
            labelPosition: "center",
            // order_state: '',
            search_Data: {
                startTime: "",
                overTime: "",
                order_id: '',
                Phone_num: "",
                // order_state:'',
                areaData: [],
                order_stateData: [
                    {
                        value: '',
                        label: '全部'
                    },
                    {
                        value: 6,
                        label: '未开始'
                    },
                    {
                        value: 1,
                        label: '进行中'
                    },
                    {
                        value: 2,
                        label: '已取消'
                    },
                    {
                        value: 3,
                        label: '已完成'
                    },
                    {
                        value: 4,
                        label: '已改期'
                    },
                    {
                        value: 5,
                        label: '已失效'
                    },
                ],

            },
            orderTableData: [
                {
                    orderTime: '2016-05-03 15:12:13',
                    area: '双人阅读区26号',
                    bookingTime: '2016-05-02 15:12:13',
                    orderPrice: 15.5,
                    cardPrice: '3小时券',
                    payOff: 5.5,
                    orderState: '进行中',
                    orderId: "20190519151213AXS",
                    phoneNum: '15525455454'
                },
            ],
            page: 1,
            limit: 5,
            total: 0,
        }
    },
    methods: {
        // 查询按钮
        onSearchBtn() {
            this.$axios({
                url: "/myorder/list",
                method: "post",
                data: {
                    page: this.page,
                    limit: this.limit,
                    // 开始时间
                    startTime: this.search_Data.startTime,
                    // 结束时间
                    endTime: this.search_Data.overTime,
                    areaId: this.search_Data.areaData,
                    // 订单状态
                    state: this.search_Data.order_stateData,
                    // 订单号
                    no: this.search_Data.order_id,
                    //  手机号
                    tel: this.search_Data.Phone_num,
                }
            }).then((res) => {
                if (res.data.code == 0) {
                    console.log(res.data.data)
                    this.total = res.data.data.count;
                    this.orderTableData = res.data.data.myorder
                } else {
                    this.$message.error("订单数据加载失败！");
                }
            });
        },
        // 取消订单
        cancelOrderId: function (row) {
            // console.log(row)
            let rowData = row;
            this.$confirm("此操作将修改订单状态, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.$axios({
                        url: "/orderseat/updateCancel",
                        method: "put",
                        params: {
                            myorderId: rowData.orderId,
                        }

                    }).then((res) => {
                        if (res.status == 200) {
                            this.$message({
                                type: "success",
                                message: "订单状态已修改.",
                            });
                            console.log('状态码',res.data.msg)
                            // let stateId = res.data.msg
                            this.$axios({
                                url: "/update/MyOrder",
                                method: "put",
                                data: {
                                    id: rowData.orderId,
                                    no: rowData.no,
                                    // 订单状态
                                    state: 2,
                                }
                            }).then((res) => {
                                this.onSearchBtn()

                                console.log('成功！！', res.data)
                            })

                        } else {
                            this.$message({
                                type: "info",
                                message: "取消修改订单修改",
                            });
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "取消修改订单修改",
                    });
                });
        },

        changePage: function (page) {
            this.page = page;
            this.onSearchBtn();
        },
    },
    mounted: function () {
        this.onSearchBtn()
    }
}


</script>


<style scoped lang="less">
#order-manage {
    width: 100%;
    height: 100%;
    // outline: 1px solid red;

    &>.title {
        line-height: 0;
        text-align: left;
    }

    & .searchInfo {
        width: 100%;
        height: 50px;
        background: #d7d7d7;
        margin-top: 30px;
        padding-left: 10px;
        box-sizing: border-box;
        position: relative;
        min-width: 1440px;

        & .search_col_top {
            width: 100%;
            height: 50px;
            display: flex;
            align-items: center;
        }

        .el-form {
            height: 50px;
        }

        .el-form-item {
            margin-bottom: 0;
        }

        .el-form-item__label {
            padding-left: 20px;
        }

        .el-button {
            position: absolute;
            right: 100px;
        }

        .el-form-item__label {
            text-align: center;
            vertical-align: middle;
            float: left;
            font-size: 14px;
            color: #606266;
            line-height: 40px;
            /* padding: 0 12px 0 0; */
            box-sizing: border-box;
        }


    }




}
</style>